package o;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.RemoteBuoyAction;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b;
import com.huawei.appmarket.service.externalapi.view.NoNetworkLoadingFragment;
import com.huawei.appmarket.service.externalapi.view.ThirdApiActivity;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.lang.ref.WeakReference;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class dyq extends dyl {
    private String ˊ = "";
    private a ˎ;

    static class a extends SafeBroadcastReceiver {
        private WeakReference<ThirdApiActivity> ˊ;
        private String ˎ = "";

        public a(ThirdApiActivity thirdApiActivity) {
            this.ˊ = new WeakReference(thirdApiActivity);
        }

        public void ˊ(String str) {
            this.ˎ = str;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            String action = intent.getAction();
            ThirdApiActivity thirdApiActivity = (ThirdApiActivity) this.ˊ.get();
            Logger.ˏ("HiAppProtocolPolicy", " onReceive tag=" + this.ˎ);
            if (thirdApiActivity != null) {
                String stringExtra = intent.getStringExtra(this.ˎ);
                if (dyq.ˏ(this.ˎ, stringExtra)) {
                    Logger.ˎ("HiAppProtocolPolicy", "key not equals " + stringExtra);
                    return;
                }
                thirdApiActivity.setRequestedOrientation(-1);
                if ("com.huawei.appmarket.startup.flow.end".equals(action)) {
                    Logger.ˎ("HiAppProtocolPolicy", " FLOW_END ");
                    FragmentManager ˏॱ = thirdApiActivity.ˏॱ();
                    Fragment findFragmentByTag = ˏॱ.findFragmentByTag("NoNetworkLoadingFragment");
                    if (findFragmentByTag != null && findFragmentByTag.ˉ()) {
                        FragmentTransaction ˊ = ˏॱ.ˊ();
                        ˊ.ˊ(findFragmentByTag);
                        ˊ.ˋ();
                    }
                    thirdApiActivity.ˋ();
                    dyq.ॱ();
                    return;
                } else if ("com.huawei.appmarket.startup.flow.interrupt".equals(action)) {
                    Logger.ˎ("HiAppProtocolPolicy", " FLOW_INTERRUPT ");
                    thirdApiActivity.ʻ();
                    return;
                } else if ("com.huawei.appmarket.startup.flow.error".equals(action)) {
                    dyq.ˊ(thirdApiActivity);
                    return;
                } else {
                    return;
                }
            }
            Logger.ˎ("HiAppProtocolPolicy", " onReceive checker is null ");
        }
    }

    static class c extends com.huawei.appmarket.service.externalapi.view.ThirdApiActivity.a {
        private WeakReference<ThirdApiActivity> ˎ;

        public c(ThirdApiActivity thirdApiActivity) {
            super(null, null);
            this.ˎ = new WeakReference(thirdApiActivity);
        }

        public boolean ˋ(TaskFragment taskFragment, b bVar) {
            return false;
        }

        public void ˎ(TaskFragment taskFragment, List<cvt> list) {
            if (this.ˎ != null) {
                ThirdApiActivity thirdApiActivity = (ThirdApiActivity) this.ˎ.get();
                if (thirdApiActivity == null) {
                    FragmentActivity ॱˋ = taskFragment.ॱˋ();
                    if (ॱˋ instanceof ThirdApiActivity) {
                        thirdApiActivity = (ThirdApiActivity) ॱˋ;
                    }
                }
                if (thirdApiActivity != null) {
                    thirdApiActivity.ॱॱ();
                }
            }
        }
    }

    class d implements dyn {
        final /* synthetic */ dyq ˊ;
        private ThirdApiActivity ˏ;

        public d(dyq o_dyq, ThirdApiActivity thirdApiActivity) {
            this.ˊ = o_dyq;
            this.ˏ = thirdApiActivity;
        }

        public void ˊ(boolean z) {
            if (!z || !this.ˊ.ॱ(this.ˏ)) {
                this.ˏ.am_();
                Fragment findFragmentByTag = this.ˏ.ˏॱ().findFragmentByTag("NoNetworkLoadingFragment");
                if (findFragmentByTag == null || !findFragmentByTag.ˉ()) {
                    this.ˏ.ͺ();
                } else {
                    this.ˏ.ॱˊ();
                }
                if (dof.ˋ(this.ˊ.ˊ)) {
                    this.ˊ.ˊ = "HiAppProtocolPolicy" + System.currentTimeMillis();
                }
                this.ˊ.ˎ.ˊ(this.ˊ.ˊ);
                Logger.ˎ("HiAppProtocolPolicy", "startPreFlow msgTag=" + this.ˊ.ˊ);
                dzw.ॱ(this.ˏ, this.ˊ.ˊ);
            }
        }
    }

    private static void ˊ(ThirdApiActivity thirdApiActivity) {
        Logger.ˎ("HiAppProtocolPolicy", " FLOW_ERROR");
        thirdApiActivity.ॱˊ();
        Fragment findFragmentByTag = thirdApiActivity.ˏॱ().findFragmentByTag("NoNetworkLoadingFragment");
        if (findFragmentByTag == null || !findFragmentByTag.ˉ()) {
            thirdApiActivity.ॱ(new c(thirdApiActivity));
        } else if (findFragmentByTag instanceof NoNetworkLoadingFragment) {
            ((NoNetworkLoadingFragment) findFragmentByTag).ॱ();
        }
    }

    private static void ॱ() {
        if (UserSession.getInstance().getStatus() == 4) {
            eox.ˎ(ContentManager.getInstant().getContext(), false);
        }
    }

    private static boolean ˏ(String str, String str2) {
        return (dof.ˋ(str) || str.equals(str2)) ? false : true;
    }

    public static void ˋ(String str) {
        euf.ˎ().ˋ("NonForceLoginCountry", str);
    }

    private static String ˎ() {
        return euf.ˎ().ॱ("NonForceLoginCountry", "");
    }

    public boolean ˏ(boolean z) {
        if (!z) {
            return false;
        }
        if (UserSession.getInstance().isLoginSuccessful()) {
            return dir.ˋ().ˏ();
        }
        if (eqp.ᐝ() || eqp.ॱ().equalsIgnoreCase(ˎ())) {
            return true;
        }
        return false;
    }

    public void ˎ(dyt o_dyt, Bundle bundle) {
        ll ˏ = ll.ˏ(ContentManager.getInstant().getContext());
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.startup.flow.interrupt");
        intentFilter.addAction("com.huawei.appmarket.startup.flow.end");
        intentFilter.addAction("com.huawei.appmarket.startup.flow.error");
        this.ˎ = new a((ThirdApiActivity) o_dyt.ˊ());
        ˏ.ˏ(this.ˎ, intentFilter);
    }

    public void ॱ(dyt o_dyt, Bundle bundle) {
    }

    public void ˋ(dyt o_dyt) {
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.ˎ);
    }

    public void ˎ(dyt o_dyt, boolean z) {
        Logger.ˎ("HiAppProtocolPolicy", "check");
        if (diu.ˊ().ˎ()) {
            Logger.ˎ("HiAppProtocolPolicy", "check onAgree ");
            exw.ˎ(o_dyt.ˊ(), "third");
            o_dyt.ˋ();
            return;
        }
        Logger.ˎ("HiAppProtocolPolicy", "check not agree");
        SafeIntent safeIntent = new SafeIntent(o_dyt.ˊ().getIntent());
        ˋ(safeIntent);
        ˏ(safeIntent, o_dyt);
        new dyp(new d(this, (ThirdApiActivity) o_dyt.ˊ())).ॱ((ThirdApiActivity) o_dyt.ˊ());
    }

    private void ˏ(SafeIntent safeIntent, dyt o_dyt) {
        Uri data = safeIntent.getData();
        if (data != null) {
            String ˏ = ceb.ˏ(data, "detailType");
            if (ACTION.HWID_SCHEME_URL.equals(safeIntent.getAction()) && "1".equals(ˏ)) {
                Intent intent = o_dyt.ˊ().getIntent();
                if (intent != null) {
                    intent.putExtra("view_type", 1);
                }
            }
        }
    }

    private void ˋ(SafeIntent safeIntent) {
        if ("com.huawei.appmarket.ext.public".equals(safeIntent.getAction())) {
            String stringExtra = safeIntent.getStringExtra("thirdId");
            if ("4026631".equals(stringExtra)) {
                epr.ˎ().ˎ(stringExtra);
            }
        }
    }

    private boolean ॱ(ThirdApiActivity thirdApiActivity) {
        String stringExtra = thirdApiActivity.getIntent().getStringExtra(RemoteBuoyAction.REMOTE_BUOY_PARAM);
        if (dof.ˋ(stringExtra)) {
            return false;
        }
        try {
            JSONObject jSONObject = new JSONArray(stringExtra).getJSONObject(0);
            if (jSONObject == null) {
                return false;
            }
            stringExtra = jSONObject.getString("pkgName");
            Logger.ˎ("HiAppProtocolPolicy", "packageName=" + stringExtra);
            if (!"com.huawei.hwid".equals(stringExtra)) {
                return false;
            }
            thirdApiActivity.ʻ();
            return true;
        } catch (JSONException e) {
            Logger.ˎ("HiAppProtocolPolicy", e.getMessage());
            return false;
        }
    }
}
